Skip to content

Preserve request exception context - #581

Open
phily245 wants to merge 4 commits into
masterfrom
phily245-literate-telegram
Open

Preserve request exception context#581
phily245 wants to merge 4 commits into
masterfrom
phily245-literate-telegram

Conversation

@phily245

Copy link
Copy Markdown
Contributor

Summary

  • preserve the original Guzzle request exception as the chained cause when request-level failures occur
  • introduce a dedicated UKFast request exception for transport/request failures
  • keep the SDK exception contract intact for request failures

Testing

  • docker run --rm -v "$PWD":/app -w /app php:8.2-cli bash -lc 'php vendor/phpunit/phpunit/phpunit --bootstrap tests/bootstrap.php tests/ApiExceptionTest.php tests/ClientTest.php'

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@phily245
phily245 requested a review from Copilot July 29, 2026 17:00
@phily245
phily245 marked this pull request as draft July 29, 2026 17:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves exception handling in the PHP SDK by preserving the original Guzzle exception as the chained cause for transport/request-level failures, while introducing a dedicated SDK RequestException for those failures.

Changes:

  • Add UKFast\SDK\Exception\RequestException and update client request handling to wrap transport/request failures with the original Guzzle exception as previous.
  • Extend SDK exception constructors to support exception chaining (code + previous) without changing the external exception contract for API failures.
  • Add a unit test asserting the original Guzzle exception is preserved when a request fails.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/ClientTest.php Adds coverage to ensure request failures preserve the original Guzzle exception as the chained cause.
src/Client.php Wraps request/transport failures in a dedicated SDK RequestException and chains original exceptions.
src/Exception/UKFastException.php Extends the base SDK exception constructor to support chaining.
src/Exception/RequestException.php Introduces a dedicated SDK exception type for transport/request failures.
src/Exception/ApiException.php Updates API exception construction to use the base constructor (supports chaining).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Exception/RequestException.php
Comment thread src/Exception/ApiException.php Outdated
Comment thread src/Exception/UKFastException.php Outdated
phily245 and others added 2 commits July 31, 2026 17:05
All it did wascopy the constructor from the parent

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@phily245
phily245 marked this pull request as ready for review July 31, 2026 16:22
@phily245
phily245 requested a review from Copilot July 31, 2026 16:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/Client.php:137

  • Client::request() now wraps all GuzzleException/RequestException failures into SDK exceptions (e.g. Exception\RequestException, Exception\ClientException, Exception\ServerException) and no longer allows GuzzleException to bubble up. The method PHPDoc still advertises @throws GuzzleException, which is misleading for SDK consumers and contradicts the new exception-contract goal of this PR. Update the docblocks for request() (and the convenience methods that delegate to it) to declare the SDK exceptions actually thrown.
            throw new Exception\RequestException($e->getMessage(), $e->getCode(), $e);
        } catch (GuzzleException $e) {
            throw new Exception\RequestException($e->getMessage(), $e->getCode(), $e);
        }

These now match what they actually are
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants